<?php

Raise::load('core.RaiseObject');
Raise::load('core.text.format.IRaiseFormatter');

/**
 * RaiseStringFormatter class
 * represents a formatter for string formatting
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.text.format
 * @since 1.2
 */
class RaiseStringFormatter extends RaiseObject implements IRaiseFormatter {

    /**
     * The format to use
     * @var string
     */
    private $format;

    /**
     * Create a new RaiseStringFormatter with a specific format
     * @param string $format The format to use when formatting, see sprintf()
     */
    public function __construct($format){
        $this->format = $format;
    }

    /**
     * Get or set the format of the date/time
     * @param string $f (optional) Set the value
     * @return string
     * @link http://php.net/sprintf
     */
    public function format($f = null){
        if(func_num_args() == 1){
            $this->format = $f;
        }
        return $this->format;
    }

    public function parse($input) {
        $a = func_get_args();
        array_unshift($a, $this->format);
        return call_user_func_array('sprintf', $a);
    }

}
